package basics;

import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author or2
 * @date 2021/8/1 15:52
 */
public class Test {

    public static void main(String[] args) throws IOException {
//        $2021_10_12();
        int capacity = 10_000, times = 10;
        StringBuilder stringBuilder = new StringBuilder(capacity);
        for (int i = 0; i < capacity; i++) stringBuilder.append(i & 0x7);
        String str = stringBuilder.toString();
        char[] chars = str.toCharArray();

        long start, end;
        start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) for (int j = 0; j < capacity; j++) System.out.print(str.charAt(j));
        end = System.currentTimeMillis();
        System.out.println();
        System.out.println(Duration.ofMillis(end-start));


        start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) for (int j = 0; j < capacity; j++) System.out.print(chars[j]);
        end = System.currentTimeMillis();
        System.out.println();
        System.out.println(Duration.ofMillis(end-start));
    }

    private static void $2021_10_12() {
        //        $2021_9_15();
//        $2021_9_24();
        int[][] intss = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
        for (int[] col : intss)
            col[0] = 0;
        System.out.println(Arrays.deepToString(intss));
//——————2021年9月26日 11点20分————— 正则表达式 —————————————————————————————————————————————————————————————————————————————————————
        String demo = new String("demo123DEMO");
        String pattern = "\\d";
        Pattern compile = Pattern.compile(pattern);
        Matcher matcher = compile.matcher(demo);
        while (matcher.find())
            System.out.println(matcher.group(0));
//——————2021年9月27日 09点51分————— 迭代方式比较 —————————————————————————————————————————————————————————————————————————————————————
        int size = 1000000;
        int[] ints = new int[size];
        for (int i = 0; i < size; size++)
            ints[i] = i;
        long start = System.currentTimeMillis();
        for (int anInt : ints) System.out.print("");
        long end = System.currentTimeMillis();
        System.out.println(Duration.ofMillis(end - start));
        start = System.currentTimeMillis();
        for (int i = 0; i < ints.length; i++) System.out.print("");
        end = System.currentTimeMillis();
        System.out.println(Duration.ofMillis(end - start));
//—————— 2021年10月4日 11点57分 ————— 各种二进制输出方式 —————————————————————————————————————————————————————————————————————————————————————
        {
            System.out.printf("%x\n", 0xabce1234);
            System.out.printf("%d\n", 0b10000000000000000000000000000000);
            System.out.printf("%b\n", 0b1111111111);
            System.out.println("123\b321");
        }
        {
            int x;
            System.out.println(x = 12);
            System.out.printf("%b\n", (x = 0) | 1);
            System.out.println(x);
            System.out.println((int) -1e9 - 1);
        }
    }

    private static void $2021_9_24() {
        System.out.println("—————————————————— 码点数组 ————————————————————————————————————");
        int[] ints = "🚫🚫🚫🚫 ⚠️".codePoints().toArray();
        for (int anInt : ints) {
            System.out.println(anInt);
        }
        String codes = new String(ints, 0, ints.length);
        System.out.println(codes);
        AtomicInteger atomicInteger = new AtomicInteger();
        int maxSize = 111411;
        Stream.generate(atomicInteger::getAndIncrement)
                .limit(maxSize)
                .map(integer -> new int[]{integer})
                .map(ints1 -> new String(ints1, 0, 1))
                .forEach(System.out::print);
    }

    private static void $2021_9_15() throws IOException {
        System.out.println(1e1);
        System.out.println(1e2);
        System.out.println("————————————————————————————————— 路 —— 径 —————————————————————————————————");
        System.out.println(System.getProperty("user.dir"));
        System.out.println(new File("").getCanonicalFile());
        System.out.println(Test.class.getResource("/"));
        System.out.println("————————————————————————————————— 并 —— 发 —————————————————————————————————");
        Callable<Void> task = () -> {
            Thread.sleep(1);
            return null;
        };
//        没有异常处理!
        ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
        singleThreadExecutor.submit(task);
        singleThreadExecutor.shutdown();
        System.out.println("————————————————————————————————— 流 —————————————————————————————————————");
        Collector<Object, ?, List<Object>> objectListCollector = Collectors.toList();
    }
}
